package com.xuexiang.xuidemo.slice.progress;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Image;

import com.xuexiang.xui_lib.component.progress.loading.RotateLoadingView;
import com.xuexiang.xuidemo.ResourceTable;

public class RotateLoadingViewSlice extends AbilitySlice {
    private Image image;
    private Button mBtSwitch;
    private RotateLoadingView rotateLoadingView;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_slice_rotateloadingview);
        initView();
        setUpView();
    }

    private void setUpView() {
        image.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                terminate();
            }
        });
        mBtSwitch.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (rotateLoadingView.isStart()) {
                    mBtSwitch.setText("开始");
                    rotateLoadingView.stop();
                } else {
                    mBtSwitch.setText("停止");
                    rotateLoadingView.start();
                }
            }
        });
    }

    private void initView() {
        image = (Image) findComponentById(ResourceTable.Id_slice_rotateloadingview_backImage);
        mBtSwitch = (Button) findComponentById(ResourceTable.Id_slice_rotateloadingview_start);
        rotateLoadingView = (RotateLoadingView) findComponentById(ResourceTable.Id_rotateLoadingView_arc_loading);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    protected void onStop() {
        super.onStop();
    }
}
